package car;

import javax.swing.*;
import java.awt.*;

public class Panel extends JPanel {
    private int speed = 0;
    private int rpm = 0;
    private int temperature = 0;
    private int fuelConsumption = 0;

    public void updateValues() {
        // 模拟数据变化
        rpm = (rpm + 50) % 8000;
        speed = (rpm / 100) % 240;
        fuelConsumption = (rpm / 100) % 100;
        temperature = (rpm / 100) % 100;
    }
    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        Graphics2D g2 = (Graphics2D) g;
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

        // 绘制速度表
        CirclePanel.drawCirclePanel(g2, 250, 30, 500, 500, 240, speed, 180, -180, 20, "%d");

        // 绘制转速表
        RingPanel.drawRingPanel(g2, 350, 350, 250, 250, 8000, rpm, Color.RED);

        // 绘制温度表
        LinePanel.drawLinePanel(g2, 50, 350, 250, 250, 100, temperature, Color.RED);

        // 绘制油耗表
        LinePanel.drawLinePanel(g2, 650, 350, 250, 250, 50, fuelConsumption, Color.BLUE);

        // 绘制数值标签
        TextPanel.drawTextPanel(g2,"Speed: " + speed + " km/h",480,200);
        TextPanel.drawTextPanel(g2,"RPM: " + rpm + " rpm",475,500);
        TextPanel.drawTextPanel(g2,"Temp: " + temperature + " °C",175,630);
        TextPanel.drawTextPanel(g2,"Fuel: " + fuelConsumption + " L/100km",775,630);

    }
}
